import pygame
import sys
import time
from test53class_morse2 import Morse


def play_morse(str):
    WIN_X = 400
    WIN_Y = 400

    BLACK = 0, 0, 0
    fps = 3
    fclock = pygame.time.Clock()

    title_name = 'MORSE'
    init_result = pygame.init()

    # Create a window
    screen = pygame.display.set_mode((WIN_X, WIN_Y))
    screen.fill(BLACK)
    pygame.display.update()
    # Set title
    pygame.display.set_caption(title_name)

    dash_file = 'mp3\\dash.mp3'
    dot_file = 'mp3\\dot.mp3'
    sleeptime = 0.3
    for s in str:
        if s == '-':
            pygame.mixer.music.load(dash_file)
            pygame.mixer.music.play()
            time.sleep(sleeptime + 0.2)
        elif s == '.':
            pygame.mixer.music.load(dot_file)
            pygame.mixer.music.play()
            time.sleep(sleeptime)
        else:
            time.sleep(sleeptime + 0.4)
    print(str)
    # i = 0
    while True:
        # font=pygame.font.Font(None,50)
        # morse_text1=font.render(str,True,(255,255,255))
        # morse_text2=font.render()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print('BYE-BYE')
                pygame.quit()
                sys.exit()
        # i += 1
        # print(i)
        fclock.tick(fps)
    # # audio_file = 'audios\wrong.m4a'


if __name__ == '__main__':
    word = 'wz'
    str = Morse().word_to_morse(word)
    print(str)
    play_morse(str)
